﻿using MusicExplorer.Common;
using MusicExplorer.Repository;
using MusicExplorer.ViewModel.Wrappers;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace MusicExplorer.ViewModel
{
    public sealed class HomePageViewModel : PageViewModelBase
    {
        public HomePageViewModel(ViewModelBase parent)
            : base(parent)
        {

        }

        private List<RepositoryWrapper> m_repositories;
        public List<RepositoryWrapper> Repositories { get { return m_repositories; } }

        protected async override Task InitializeAsync(NavigationObject obj)
        {
            m_repositories = new List<RepositoryWrapper>();

            var repositories = await RepositoryHelper.GetRepositoriesAsync();
            foreach (var repo in repositories)
                m_repositories.Add(new RepositoryWrapper(this, repo));
        }

        public override string Title { get { return "MusicExplorer"; } }

        private RepositoryWrapper m_selectedRepository;
        public RepositoryWrapper SelectedRepository
        {
            get { return m_selectedRepository; }
            set
            {
                if(m_selectedRepository != value)
                {
                    m_selectedRepository = value;
                    RaisePropertyChanged();

                    //m_navigationService.Navigate(typeof(RepositoryPageViewModel), new NavigationObject(this, m_selectedRepository.Entity));
                }
            }
        }
    }
}
